home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / tutorials / custEducation / opengl1 / lib / window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.4 KB  |  156 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18.  
  19. #include <aux.h>
  20. #include <auxPrivate.h>
  21.  
  22. /**************************************************************************
  23.  *   auxGetWindow() - Match an X window to an auxWindow id
  24.  **************************************************************************/
  25.  
  26. auxWindow *
  27. auxGetWindow( GLint windowId )
  28. {
  29.     auxWindow          *tmp;
  30.  
  31.     for ( tmp = auxState.head; tmp; tmp = tmp->next )
  32.         if ( tmp->id == windowId )
  33.             return tmp;
  34.     auxFatalError( "Unable to find window" );
  35. }
  36.  
  37.  
  38. /**************************************************************************
  39.  *   auxWinSet() - make a window the current drawable
  40.  **************************************************************************/
  41.  
  42. GLvoid
  43. auxWinSet( GLint windowId )
  44. {
  45.     auxWindow            *tmp;
  46.  
  47. #ifdef DEBUG
  48.     printf("   In auxWinSet() ...  windowId = %d\n", windowId );
  49. #endif
  50.  
  51.     if ( windowId < ZERO )
  52.         tmp = auxState.current;
  53.     else
  54.         tmp = auxGetWindow( windowId );
  55.  
  56. #ifdef DEBUG
  57.     printf( "   In auxWinSet() ... about to call glXMakeCurrent()\n\n" );
  58.     printf( "\tid = %d\n", tmp->id );
  59.     printf( "\tglxWindow = 0x%x\n", tmp->glxWindow );
  60.     printf( "\tglxContext = 0x%x\n", tmp->glxContext );
  61. #endif
  62.  
  63.     if ( !glXMakeCurrent( auxState.display, tmp->glxWindow, tmp->glxContext ) )
  64.         auxFatalError( "Unable to set window" );
  65. }
  66.  
  67.  
  68. /**************************************************************************
  69.  *   auxWinGet() - return the current grahics window id
  70.  **************************************************************************/
  71.  
  72. GLint
  73. auxWinGet( GLvoid )
  74. {
  75.     return auxState.current->id;
  76. }
  77.  
  78. /**************************************************************************
  79.  *   auxWinClose() - Destroy a window
  80.  **************************************************************************/
  81.  
  82. GLvoid
  83. auxWinClose( GLint windowId )
  84. {
  85.     auxWindow            *tmp;
  86.  
  87.     tmp = auxGetWindow( windowId );
  88.  
  89.     if ( !tmp->prev ) {                       /* Head of list */
  90.         auxState.head = tmp->next;
  91.         auxState.head->prev = (auxWindow *) NULL;
  92.     } else if ( !tmp->next ) {                /* Tail of list */
  93.         auxState.tail = tmp->prev;
  94.         auxState.tail->next = (auxWindow *) NULL;
  95.     } else {                                  /* Somewhere in middle of list */
  96.         tmp->next->prev = tmp->prev;    
  97.         tmp->prev->next = tmp->next;
  98.     }
  99.  
  100.     XUnmapWindow( auxState.display, tmp->glxWindow );
  101.     glXDestroyContext( auxState.display, tmp->glxContext );
  102.     XDestroyWindow( auxState.display, tmp->glxWindow );
  103.  
  104.     free( tmp );
  105. }
  106.  
  107.  
  108. /**************************************************************************
  109.  *   auxSwapBuffers() - swap the front and back buffers
  110.  **************************************************************************/
  111.  
  112. GLvoid
  113. auxSwapBuffers( GLvoid )
  114. {
  115.     glXSwapBuffers( auxState.display, auxState.current->glxWindow );
  116. }
  117.  
  118.  
  119. /**************************************************************************
  120.  *   auxGetSize() - retrieve the size of a window
  121.  **************************************************************************/
  122.  
  123. GLvoid
  124. auxGetSize( GLsizei *width, GLsizei *height )
  125. {
  126.     *width = auxState.current->width;
  127.     *height = auxState.current->height;
  128. }
  129.  
  130.  
  131. /**************************************************************************
  132.  *   auxGetOrigin() - retrieve the position of a window
  133.  **************************************************************************/
  134.  
  135. GLvoid
  136. auxGetOrigin( GLint *x, GLint *y )
  137. {
  138.     *x = auxState.current->x;
  139.     *y = auxState.current->y;
  140. }
  141.  
  142.  
  143. /**************************************************************************
  144.  *   auxGetScreenSize() - retrieve the size of a window
  145.  **************************************************************************/
  146.  
  147. GLvoid
  148. auxGetScreenSize( GLsizei *width, GLsizei *height )
  149. {
  150.     if ( !auxInitCalled )
  151.         auxInit();
  152.  
  153.     *width = WidthOfScreen( auxState.screen );
  154.     *height = HeightOfScreen( auxState.screen );
  155. }
  156.